﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace testing_thing
{
    public class CommandProcessor
    {
        public CommandProcessor()
        {
            LookCommand lc = new LookCommand();
            TransferCommand tc = new TransferCommand();
            MoveCommand mc = new MoveCommand();
            addCommand(lc);
            addCommand(tc);
            addCommand(mc);
        }
        private List<Command> cmd = new List<Command>();

        public string Run(Player p, string input)
        {
            string result = "";
            string[] commandSplit = input.Replace(" and ", "|").ToLower().Split('|');

            

            foreach (string command in commandSplit)
            {
              
                bool found = false;
                string[] inputSplit = command.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
                if (command == "" || command == null || inputSplit.Length<=0)
                {
                    result += "please enter a command\n";
                    return result;
                }
                else
                {

                    foreach (Command c in cmd)
                    {
                        if (c.IdentifiedBy(inputSplit[0]) || c.IdentifiedBy(command))
                        {
                            result += c.Run(p, inputSplit) + "\n\n";
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) result += "I don't understand how to " + input + "\n\n";
            }

            return result;
        }

        private void addCommand(Command c)
        {
            cmd.Add(c);
        }

    }
}
